// 更简洁的版本
(function (win, doc) {
  "use strict";

  function Router(option) {
    this.routes = option.routes;
    this.viewHandle = option.viewHandle;
    this.currentUrl = '';

    this.v = {};
    this._init();
  }

  Router.prototype._binEvent = function () {
    win.addEventListener('load', this.refresh.bind(this), false);
    win.addEventListener('hashchange', this.refresh.bind(this), false);
  };

  Router.prototype.refresh = function () {
    var hash = win.location.hash;
    if (!hash) {
      win.location.hash = '/';
      return;
    }

    this.currentUrl = hash.match(/#([\/\w]*)/)[1];
    var mothod = this.routes[this.currentUrl];

    if (mothod) {
      this.viewHandle(mothod);
    }
  };

  Router.prototype._init = function () {
    this._binEvent();
  };

  Router.prototype.go = function (path, data) {
    win.location.hash = path;
    this.v.data = data;
  }

  win.Router = Router;
})(window, document);
